namespace dbm2.Model
{
    public class FieldConstraints
    {
        public bool IsFK { get; private set;}
        private Field FKField;

        public bool IsCheckSetted { get; private set; }
        private string predicate;

        public bool IsDefaultValueSet { get; private set; }
        private string defaultValue;

        public string PKName { get; set; }
        public string FKName { get; set; }

        public bool IsUnique { get; set; }

        // If true = can be null
        public bool IsNullable { get; set; }

        public bool IsPK {get; set;}

        public FieldConstraints()
        {
            IsNullable = true;
        }

        public void SetFKField(Field fkField, string name)
        {
            FKField = fkField;
            IsFK = true;
            FKName = name;
        }

        public Field GetFKField()
        {
            if (!IsFK)
                return null;
            return FKField;
        }

        public void SetCheck(string predicate)
        {
            this.predicate = predicate;
            IsCheckSetted = true;
        }

        public void SetDefaultValue(string value)
        {
            IsDefaultValueSet = true;
            defaultValue = value;
        }
    }
}